<html>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>


<a href ="editcustomer.php" target = "_top">Edit another Customer</a><br />

</html>

<?php

if(isset($_POST['origID']))
{
    $username="bsc353_4";
    $password="sonbeans";
    $database="bsc353_4";
    mysql_connect("clipper.encs.concordia.ca",$username,$password);

    @mysql_select_db($database) or die ("Unable to select database");


    $originalID = $_POST['origID'];
    

    if (isset($_POST['delete'])) //if user chose to delete
    {
        $query = "DELETE FROM Customer WHERE ID = '$originalID'";
    }
    else //user chose to edit one or more of the book's fields
    {
        $ID=$_POST['ID'];
        $name=$_POST['name'];
        $address=$_POST['address'];
        $province=$_POST['province'];
        $postalCode=$_POST['postalCode'];
        $phoneNumber=$_POST['phoneNumber'];
        $city = $_POST['city'];
        $numPurchases= intval($_POST['numPurchases']);
        
        $query="UPDATE Customer SET ID='$ID', name = '$name', address = '$address', city = '$city', province = '$province', postalCode = '$postalCode',
        phoneNumber = '$phoneNumber', numPurchases = $numPurchases WHERE ID = '$originalID';";

        //echo $query;
    }
    
    //echo $query;
    mysql_query($query) or die ("failed to edit record");

    if(isset($_POST['save']))
        echo "Record successfully edited";
    else if(isset($_POST['delete']))
        echo "Record successfully deleted";
	
    mysql_close();
}
else
{
    echo "need to choose a customer first";
}



?> 

